package com.shangcheng.server.controller;

import com.shangcheng.model.domain.CmsSubject;
import com.shangcheng.model.dto.CmsSubjectAndCategoryName;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.CmsSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JavaClimber
 * @version 1.0
 * @date 2022/5/12 0012 zihao
 * 获取所有商品优选
 */
@RestController
@RequestMapping("/subject")
public class CmsSubjectController {
    @Autowired
    private CmsSubjectService cmsSubjectService;

    //根据专题名称分页获取商品专题
    @GetMapping("/list")
    public ResponseEntity listAll(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10")
            Integer pageSize, String keyword) {
        //调用service
        PageResult lists = cmsSubjectService.lists(keyword, pageNum, pageSize);
        //返回对象
        return ResponseEntity.ok(new Result(200, lists, "成功"));
    }

    //获取全部商品专题
    @GetMapping("/listAll")
    public ResponseEntity listAll(){
        List<CmsSubjectAndCategoryName> list = cmsSubjectService.listAll();
        return ResponseEntity.ok(new Result(200, list, "成功"));

    }

}
